package in.jiemin.springboot.config;

import in.jiemin.springboot.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Configuration
public class ThriftConfig {



    public static Map<String, HelloService.Client> serviceMap = new HashMap<>();



    @PostConstruct
    public void createClient(){
        log.info("thrift客户端正在初始化");
        TSocket tSocket = new TSocket("127.0.0.1", 7911);

        try {
            tSocket.open();
            log.info("正在添加 helloService 到 注册表中");
            serviceMap.put("helloService", new HelloService.Client(new TBinaryProtocol(tSocket)));
        } catch (TTransportException e) {
            e.printStackTrace();
        }

    }



}
